﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;

namespace GSLMS.Entity
{
    /// <summary>
    /// 2.3.22    待处理信息表（中间表）
    /// </summary>
    [DataContract(IsReference = true)]
    public class TB_APP_SHOULDDOINFO : IObjectWithChangeTracker, INotifyPropertyChanged
    {
        //提出日期
        //操作
        //客户名称
        //证件号码
        //产品名称
        //产品记录ID
        //类别,1待分配，2立项申请待审批，3转介申请待处理，4特批申请待审批，5展期申请待审批，6费用减免待审批

        private DateTime? _applyDate;
        private string _operType;
        private string _custName;
        private string _custNo;
        private string _productName;
        private long _productID;
        private int _InfoType;
        private long _pid;
        private int _AuditType;
        private int _systemID;

        /// <summary>
        /// 1项目经理审批，2项目总经理审批
        /// </summary>
        public int AuditType
        {
            set { _AuditType = value; }
            get { return _AuditType; }
        }


        /// <summary>
        /// 提出日期
        /// </summary>
        public DateTime? ApplyDate
        {
            set { _applyDate = value; }
            get { return _applyDate; }
        }

        /// <summary>
        /// 操作
        /// </summary>
        public string OperType
        {
            set { _operType = value; }
            get { return _operType; }
        }

        /// <summary>
        /// 客户名称
        /// </summary>
        public string CustName
        {
            set { _custName = value; }
            get { return _custName; }
        }

        /// <summary>
        /// 证件号码
        /// </summary>
        public string CustNO
        {
            set { _custNo = value; }
            get { return _custNo; }
        }

        /// <summary>
        /// 产品名称
        /// </summary>
        public string ProductName
        {
            set { _productName = value; }
            get { return _productName; }
        }

        /// <summary>
        /// 产品记录ID
        /// </summary>
        public long PorductID
        {
            set { _productID = value; }
            get { return _productID; }
        }

        /// <summary>
        /// 类别,1待分配，2立项申请待审批，3转介申请待处理，4特批申请待审批，5展期申请待审批，6费用减免待审批,
        /// 7、风控分配, 8、待首席风控官审批，9、待出款审批，10、合同待审批，11贷款审议待审批
        /// </summary>
        public int InfoType
        {
            set { _InfoType = value; }
            get { return _InfoType; }
        }


      

        /// <summary>
        /// 父ID与类别相对应
        /// </summary>
        public long PID
        {
            set { _pid = value; }
            get { return _pid; }
        }

        public long ID
        {
            set;
            get;
        }

        /// <summary>
        /// 系统记录ID
        /// </summary>
        public int SystemID
        {
            set { _systemID = value; }
            get { return _systemID; }
        }

        

        public string Detail
        {
            get
            {
                if(InfoType==1||InfoType==2)
                    return string.Format(@"{0}【{1}】{2}【{3}】{4}", (ApplyDate == null ? "" : ApplyDate.Value.ToString("yyyy年MM月dd日")), CustName, OperType, ProductName, (Category)InfoType);
                else
                    return string.Format(@"{0}提出【{1}】{2}", (ApplyDate == null ? "" : ApplyDate.Value.ToString("yyyy年MM月dd日")), CustName, (Category)InfoType);
            }
        }

        public string DetailRiskAudit
        {
            get
            {
                if (InfoType ==8)
                    return string.Format(@"【{0}】{1}【{2}】{3}【{4}】{5}", (GSLMS.Entity.Enum.ApplyEnum.RegSystemID)SystemID, (ApplyDate == null ? "" : ApplyDate.Value.ToString("yyyy年MM月dd日")), CustName, "", ProductName, (Category)InfoType);
                else
                    return string.Format(@"【{0}】{1}提出【{2}】{3}", (GSLMS.Entity.Enum.ApplyEnum.RegSystemID)SystemID, (ApplyDate == null ? "" : ApplyDate.Value.ToString("yyyy年MM月dd日")), CustName, (Category)InfoType);
            }
        }

        public string DetailHighAudit
        {
            get
            {
                if (InfoType == 2 || InfoType == 8)
                    return string.Format(@"【{0}】{1}【{2}】{3}【{4}】{5}", (GSLMS.Entity.Enum.ApplyEnum.RegSystemID)SystemID, (ApplyDate == null ? "" : ApplyDate.Value.ToString("yyyy年MM月dd日")), CustName, "", ProductName, (Category)InfoType);
                else
                    return string.Format(@"【{0}】{1}提出【{2}】{3}", (GSLMS.Entity.Enum.ApplyEnum.RegSystemID)SystemID, (ApplyDate == null ? "" : ApplyDate.Value.ToString("yyyy年MM月dd日")), CustName, (Category)InfoType);
            }
        }

        public string URL
        {
            get
            {
                string url = string.Empty;
                switch (InfoType)
                {
                    case 1:
                        url = "DianDang/BMAudit/bManager/GRefRegInfo/" + PID;
                        break;
                    case 2:
                        url = "DianDang/BMAudit/" + (AuditType == 1 ? "bManager" : "gManager") + "/GProInfo/" + PID;
                        break;
                    case 3:
                        url = "DianDang/BMAudit/bManager/GAuditRefRegInfo/" + PID;
                        break;
                    case 4:
                        url = "DianDang/BMAudit/" + (AuditType == 1 ? "bManager" : "gManager") + "/GSpecailInfo/" + PID;
                        break;
                    case 5:
                        url = "DianDang/BMAudit/" + (AuditType == 1 ? "bManager" : "gManager") + "/GLoanExt/" + PID;
                        break;
                    case 6:
                        url = "DianDang/BMAudit/" + (AuditType == 1 ? "bManager" : "gManager") + "/GFeesFree/" + PID;
                        break;
                        //首席风控官审批 7、风控分配, 8、待首席风控官审批，9、展期申请待审批、10待出款审批，11、合同待审批，12贷款审议待审批
                    case 7:
                        url = "RiskAudit/Director/DirectorDefault/GAssign/" + PID;
                        break;
                    case 8:
                        url = "RiskAudit/Director/DirectorDefault/GApplyAudit/" + PID;
                        break;
                    case 9:
                        url = "RiskAudit/Director/DirectorDefault/GExtAudit/" + PID;
                        break;
                    case 10:
                        url = "RiskAudit/Director/DirectorDefault/GLoanApply/" + PID;
                        break;
                    case 11:
                        url = "RiskAudit/Director/DirectorDefault/GLoanCon/" + PID;
                        break;
                    case 12:
                        url = "RiskAudit/Director/DirectorDefault/GConAudit/" + PID;
                        break;

                }
                return url;
            }
        }

        public string RiskURL
        {
            get
            {
                string url = string.Empty;
                switch (InfoType)
                {
                    
                    //首席风控官审批 7、风控分配, 8、待首席风控官审批，9、展期申请待审批、10待出款审批，11、合同待审批，12贷款审议待审批
                    case 7:
                        url = "RiskAudit/Director/DirectorDefault/GAssign/" + PID;
                        break;
                    case 8:
                        url = "RiskAudit/Director/DirectorDefault/GApplyAudit/" + PID;
                        break;
                    case 9:
                        url = "RiskAudit/Director/DirectorDefault/GExtAudit/" + PID;
                        break;
                    case 10:
                        url = "RiskAudit/Director/DirectorDefault/GLoanApply/" + PID;
                        break;
                    case 11:
                        url = "RiskAudit/Director/DirectorDefault/GLoanCon/" + PID;
                        break;
                    case 12:
                        url = "RiskAudit/Director/DirectorDefault/GConAudit/" + PID;
                        break;

                }
                return url;
            }
        }


        public string HighURL
        {
            get
            {
                string url = string.Empty;
                switch (InfoType)
                {
                    // 8、立项申请待审批，9、展期申请待审批、10待出款审批，11、合同待审批，12贷款审议待审批
                    case 4:
                        url = "HighAudit/DirectorAdu/GSpecailAudit/" + PID;
                        break;
                    case 6:
                        url = "HighAudit/DirectorAdu/GFeesFree/" + PID;
                        break;
                    case 2:
                        url = "HighAudit/DirectorAdu/GApplyAudit/" + PID;
                        break;
                    case 9:
                        url = "HighAudit/DirectorAdu/GExtAudit/" + PID;
                        break;
                    case 10:
                        url = "HighAudit/DirectorAdu/GLoanApply/" + PID;
                        break;
                    case 11:
                        url = "HighAudit/DirectorAdu/GLoanCon/" + PID;
                        break;
                    case 12:
                        url = "HighAudit/DirectorAdu/GConAudit/" + PID;
                        break;
                    case 13:
                        url = "HighAudit/DirectorAdu/GExcLoanIn/" + PID;
                        break;
                    case 14:
                        url = "HighAudit/DirectorAdu/GExcLoanOut/" + PID;
                        break;

                }
                return url;
            }
        }


        #region ChangeTracking

        protected virtual void OnPropertyChanged(String propertyName)
        {
            if (ChangeTracker.State != ObjectState.Added && ChangeTracker.State != ObjectState.Deleted)
            {
                ChangeTracker.State = ObjectState.Modified;
            }
            if (_propertyChanged != null)
            {
                _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        protected virtual void OnNavigationPropertyChanged(String propertyName)
        {
            if (_propertyChanged != null)
            {
                _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { add { _propertyChanged += value; } remove { _propertyChanged -= value; } }
        private event PropertyChangedEventHandler _propertyChanged;
        private ObjectChangeTracker _changeTracker;

        [DataMember]
        public ObjectChangeTracker ChangeTracker
        {
            get
            {
                if (_changeTracker == null)
                {
                    _changeTracker = new ObjectChangeTracker();
                    _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
                }
                return _changeTracker;
            }
            set
            {
                if (_changeTracker != null)
                {
                    _changeTracker.ObjectStateChanging -= HandleObjectStateChanging;
                }
                _changeTracker = value;
                if (_changeTracker != null)
                {
                    _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
                }
            }
        }

        private void HandleObjectStateChanging(object sender, ObjectStateChangingEventArgs e)
        {
            if (e.NewState == ObjectState.Deleted)
            {
                ClearNavigationProperties();
            }
        }

        protected bool IsDeserializing { get; private set; }

        [OnDeserializing]
        public void OnDeserializingMethod(StreamingContext context)
        {
            IsDeserializing = true;
        }

        [OnDeserialized]
        public void OnDeserializedMethod(StreamingContext context)
        {
            IsDeserializing = false;
            ChangeTracker.ChangeTrackingEnabled = true;
        }

        protected virtual void ClearNavigationProperties()
        {
        }

        #endregion

        enum Category
        {
            待分配 = 1,
            立项申请待审批 = 2,
            转介申请待处理 = 3,
            特批申请待审批 = 4,
            展期申请待审批 = 5,
            费用减免待审批 = 6,
            风控待分配=7,
            待首席风控官审批=8,
            贷款展期待审批=9,
            待出款审批=10,
            合同待审批=11,
            贷款审议待审批=12,
            拆借借入待审批 = 13,
            拆借借出待审批 = 14

            //首席风控官审批 7、风控分配, 8、待首席风控官审批，9、展期申请待审批、10待出款审批，11、合同待审批，12贷款审议待审批
            //13
        }
    }
}
